package com.qiezikaka.kaka.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.makeramen.roundedimageview.RoundedImageView;
import com.qiezikaka.kaka.R;
import com.qiezikaka.kaka.bean.FuZhuangInfo;
import com.qiezikaka.kaka.bean.SiteSceneShowInfo;

import java.util.List;


/**
 *
 */
public class FengGeSceneAdapter extends BaseQuickAdapter<SiteSceneShowInfo.DataBean, BaseViewHolder> {

    public FengGeSceneAdapter(int layoutResId, List<SiteSceneShowInfo.DataBean> data) {
        super(layoutResId, data);

    }
    private int position = 0;
    public void choicePostion(int position){
        this.position = position;
    }


    @Override
    protected void convert(BaseViewHolder helper,SiteSceneShowInfo.DataBean item) {
        LinearLayout ll_kuan = helper.getView(R.id.ll_kuan);

        int adapterPosition = helper.getAdapterPosition();
        if(adapterPosition == position){
            ll_kuan.setBackgroundResource(R.drawable.bg_yu_kuan);
        }else{
            ll_kuan.setBackgroundResource(R.drawable.bg_yu_kuan_normal);
        }

        ViewTreeObserver observer = helper.getView(R.id.ll_kuan).getViewTreeObserver();
        observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                helper.getView(R.id.ll_kuan).getViewTreeObserver().removeOnGlobalLayoutListener(this);
                ViewGroup.LayoutParams layoutParams = helper.getView(R.id.ll_kuan).getLayoutParams();
                int width = helper.getView(R.id.ll_kuan).getMeasuredWidth();
                layoutParams.height = width*5/4;
                helper.getView(R.id.ll_kuan).setLayoutParams(layoutParams);
            }
        });


        Glide.with(mContext)
                .load(item.getThumb())
//                .placeholder(R.drawable.placeholder_image) // 占位符图片
//                .error(R.drawable.error_image) // 错误时显示的图片
                .into((RoundedImageView)helper.getView(R.id.iv_bg_scene));

    }

    @Override
    public int getItemCount() {
        return 4;
    }
}


